layui.use(['layer','form','table','element'],function () {
    var layer = layui.layer
        ,form = layui.form
        ,table =layui.table
        ,element = layui.element;

    //初始化数据表格
     table.render({
         elem:"#data"
         ,height: 'full-150'
         ,url:"/admin/user/getNewsTableData"
         ,cellMinWidth: 80
         ,cols: [[
             {field:'content',width:550, title: '消息内容',align:'center'}
             ,{field:'showCreateTime',width:190,title: '通知时间',sort: true,align:'center'}
             ,{field:'',width:90,title: '状态',toolbar: '#statusBar',align:'center'}
             ,{field:'',width:280,title: '操作',toolbar: '#barDemo',align:'center'}
         ]]
         ,page:true
     });

    //监听工具条
    table.on('tool(dataTable)',function (obj) {
        var data = obj.data;
        if(obj.event == 'detail'){
            $.ajax({
                url:"/admin/user/readNews",
                type:"POST",
                dataType:"json",
                data:{
                    "id":data.id
                },
                success:function (result) {
                    if(result.flag){
                        layer.open({
                            type: 1
                            ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                            ,id: 'layerDemoauto' //防止重复弹出
                            ,content: '<div style="padding: 20px;">'+ data.content +'</div>'
                            ,btn: '关闭全部'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                                layer.closeAll();
                                table.reload("data");
                            }
                        });
                    }else{
                        layer.msg(result.message);
                    }
                },
                error:function () {
                    layer.msg("系统错误！");
                }
            });
        }
    });

     //搜索
    $("#search").on("click",function () {
        table.reload("data",{
            page:{
                curr:1
            }
            ,where:{
                isRead:$("#isRead").val(),
            }
        })
    });;


});
